package com.prs.crm.action.sale;

import java.util.Collection;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.action.FlowAction;
import com.prs.crm.annotation.Clew;
import com.prs.crm.annotation.FlowActive;
import com.prs.crm.annotation.FlowStart;
import com.prs.crm.domain.sale.SalesStoreOut;
import com.prs.crm.domain.sale.SalesStoreOutDetail;
import com.prs.crm.domain.stock.Product;
import com.prs.crm.domain.store.StoreRoom;
import com.prs.crm.service.sale.SalesStoreOutService;
import com.prs.crm.service.stock.StoreRoomService;

public class SalesStoreOutAction  extends FlowAction<SalesStoreOut> {
	
	private static final long serialVersionUID = 1L;
	
	private Integer[] storeOuts;
	
	private Product[] products;
	
	private StoreRoom[] rooms;
	
	private String[] productNames;
	
	private Integer[] storeNums;
	
	private Integer[] ContractNums;
			
	private SalesStoreOut salesStoreOut;
	
	private SalesStoreOutService salesStoreOutService;
	
	private StoreRoomService   storeRoomService;
	
	private PaginationSupport pagination;
	
	private Collection<SalesStoreOutDetail> slist;
	
	/**
	 * 库房
	 * @return
	 */
	private List<StoreRoom> roomlist;
	
	
	    @FlowActive(target = "salesStoreOut", flowservice = "salesStoreOutService")
		@Action("editSalesStoreOut")
		public String editSalesStoreOut() {

			this.roomlist=this.getStoreRoomService().getAllstoreroom();
			return SUCCESS;
		}

		@Clew(results = { "success", "none" })
		@FlowStart(target = "salesStoreOut", flowservice = "salesStoreOutService")
		@Action(value = "saveSalesStoreOut", results = {
				@Result(name = "success", type = "redirect", location = "listSalesStoreOut"),
				@Result(name = "error", type = "chain", location = "editSalesStoreOut"),
				@Result(name = "none", type = "redirect", location = "listSalesStoreOut") })
		public String saveSalesStoreOut() {	
			if(products==null){
				this.addActionError("产品不能为空");
				return ERROR;
			}
			this.getSalesStoreOutService().saveAllSaleStoreOut(salesStoreOut, products, productNames, storeNums, ContractNums, rooms);
	        this.setPrompt("操作成功");
			return SUCCESS;
		}

		@Action("listSalesStoreOut")
		public String excute() {
			DetachedCriteria criteria = this.getPaginationHelper().createQuery(
					SalesStoreOut.class);
			pagination = this.getPaginationHelper().prepare(pagination);
			this.setPagination(this.getSalesStoreOutService().listByPage(criteria,
					pagination));
			return SUCCESS;
		}

		@Action("viewSalesStoreOut")
		public String viewSalesStoreOut() {
			salesStoreOut = this.getSalesStoreOutService().get(salesStoreOut.getId());
			this.slist = salesStoreOut.getDetails();
			this.displayEndNodes(salesStoreOut);
			return SUCCESS;
		}

		public SalesStoreOut getSalesStoreOut() {
			return salesStoreOut;
		}

		public void setSalesStoreOut(SalesStoreOut salesStoreOut) {
			this.salesStoreOut = salesStoreOut;
		}

		public SalesStoreOutService getSalesStoreOutService() {
			return salesStoreOutService;
		}

		public void setSalesStoreOutService(SalesStoreOutService salesStoreOutService) {
			this.salesStoreOutService = salesStoreOutService;
		}

		public StoreRoomService getStoreRoomService() {
			return storeRoomService;
		}

		public void setStoreRoomService(StoreRoomService storeRoomService) {
			this.storeRoomService = storeRoomService;
		}

		public PaginationSupport getPagination() {
			return pagination;
		}

		public void setPagination(PaginationSupport pagination) {
			this.pagination = pagination;
		}

		public List<StoreRoom> getRoomlist() {
			return roomlist;
		}

		public void setRoomlist(List<StoreRoom> roomlist) {
			this.roomlist = roomlist;
		}

		public Integer[] getStoreOuts() {
			return storeOuts;
		}

		public void setStoreOuts(Integer[] storeOuts) {
			this.storeOuts = storeOuts;
		}

		public Product[] getProducts() {
			return products;
		}

		public void setProducts(Product[] products) {
			this.products = products;
		}

		public String[] getProductNames() {
			return productNames;
		}

		public void setProductNames(String[] productNames) {
			this.productNames = productNames;
		}

		public Integer[] getStoreNums() {
			return storeNums;
		}

		public void setStoreNums(Integer[] storeNums) {
			this.storeNums = storeNums;
		}

		public Integer[] getContractNums() {
			return ContractNums;
		}

		public void setContractNums(Integer[] contractNums) {
			ContractNums = contractNums;
		}

		public StoreRoom[] getRooms() {
			return rooms;
		}

		public void setRooms(StoreRoom[] rooms) {
			this.rooms = rooms;
		}

		public Collection<SalesStoreOutDetail> getSlist() {
			return slist;
		}

		public void setSlist(Collection<SalesStoreOutDetail> slist) {
			this.slist = slist;
		}

		
	

}
